<form id="sysSecurityForm">
    <div class="form-body">
        <div class="form-title" data-trans="system_security"></div>
        <div class="content">
            <div class="row-fluid">
                <label class="span4 side-right" data-trans="remote_management"></label>
                <div class="span8">
                    <input type="radio" name="remoteGrp" id="remoteEnable" data-bind="checked: remoteFlag" value="1" />
                    <label for="remoteEnable" data-trans="enable"></label>
                    <input type="radio" name="remoteGrp" id="remoteDisable" data-bind="checked: remoteFlag" value="0" />
                    <label for="remoteDisable" data-trans="disable"></label>
                </div>
            </div>
            <div class="row-fluid">
                <label class="span4 side-right" data-trans="ping_from_wan"></label>
                <div class="span8">
                    <input type="radio" name="pingGrp" id="pingEnable" data-bind="checked: pingFlag" value="1" />
                    <label for="pingEnable" data-trans="enable"></label>
                    <input type="radio" name="pingGrp" id="pingDisable" data-bind="checked: pingFlag" value="0" />
                    <label for="pingDisable" data-trans="disable"></label>
                </div>
            </div>
        </div>
        <div class="form-buttons">
            <input type="submit" class="btn-1 " data-trans="apply" />
            <input type="button" data-bind="click: clear" class="btn-1 " data-trans="cancel" />
        </div>
    </div>
</form>

<script>
    $(function() {
        var service = window._service;
        var config = service.config;

        /**
         * system security VM
         * @class SysSecurityModeVM
         */
        function SysSecurityModeVM() {
            var self = this;
            var info = getSysSecurity();

            self.remoteFlag = ko.observable(info.remoteFlag);
            self.pingFlag = ko.observable(info.pingFlag);

            self.clear = function() {
                init();
            };

            self.save = function() {
                showLoading();
                var params = {};
                params.remoteFlag = self.remoteFlag();
                params.pingFlag = self.pingFlag();
                service.setSysSecurity(params, function(result) {
                    if (result.result == "success") {
                        successOverlay();
                    } else {
                        errorOverlay();
                    }
                });

            };
        }

        /**
         * 获取system security 信息
         * @method getSysSecurity
         */
        function getSysSecurity() {
            return service.getSysSecurity();
        }

        /**
         * 初始化system security mode view model
         * @method init
         */
        function init() {
            var container = $('#sysSecurityForm');
            ko.cleanNode(container[0]);
            var vm = new SysSecurityModeVM();
            ko.applyBindings(vm, container[0]);
            $('#sysSecurityForm').validate({
                submitHandler: function() {
                    vm.save();
                }
            });
        }

        init();
        $('#sysSecurityForm').translate();
    });
</script>